//重置样式
require('../../assets/css/index.less')

//引入weui库
require('../../assets/lib/weui/weui.css')
let weui = require('../../assets/lib/weui/weui.js')

//当前页面样式
require('./login.less')

//引入dom
const dom = require('../../utils/dom.js')
//引入axios
const https = require('../../utils/https.js')
//引入存储
const local = require('../../utils/local.js')

dom.reday(function(){
    //点击跳转注册
    dom.getEvent('#regUser',function(){
        location.href='register.html'
    })

    dom.getEvent('#loginBtn',function(){
        //都有值再发送ajax
        if(inp1.value&&inp2.value){
            https.post('/api/user/login',{
                account: inp1.value,
                password: inp2.value
            },function(data){
                // console.log(data);
                if(data.errno==0){//登陆成功
                    local.set('token',data.data.token)
                    location.href='home.html'
                    // alert('登陆成功')
                }else{//登陆失败
                    // alert('账号或密码有误');
                    weui.topTips('账号或密码有误')
                }
            })
        }else{
            // alert('请输入账号和密码')
            weui.topTips('请输入账号和密码')
        }
    })

})